package com.prs.crm.dao.person.impl;

import java.util.Collection;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import com.prs.crm.dao.impl.BaseDaoImpl;
import com.prs.crm.dao.person.DepartmentDao;
import com.prs.crm.domain.person.Department;

public class DepartmentDaoImpl extends BaseDaoImpl<Department> implements DepartmentDao{

	@SuppressWarnings("unchecked")
	@Override
	public List<Department> getAllDepartment() {
		Criteria criteria=this.getSession().createCriteria(Department.class);
		return criteria.list();
	}
//
//	@Override
//	public List<Department> getDepartmentByDeptId(Integer deptId) {
//		Criteria criteria=this.getSession().createCriteria(Department.class)
//		.add(Restrictions.eq("department.id", deptId));
//		return criteria.list();
//	}

	@SuppressWarnings("unchecked")
	@Override
	public Collection<Department> getRootDepartment() {
		Criteria criteria=this.getSession().createCriteria(Department.class);
		criteria.add(Restrictions.isNull("parent"));
		criteria.addOrder(Order.asc("id"));
		return criteria.list();
	}

}
